import pagesConfig from '@/pages.json'; // 根据实际路径调整
export default {
	// 监听用户点击右上角菜单的「转发」按钮时触发的事件
	onShareAppMessage() {
		this.$store.dispatch('common/getRelay')
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1];
		const pagePath = currentPage.route;

		// 查找主包和分包中的页面配置
		let pageConfig = null;

		// 查找主包
		pageConfig = pagesConfig.pages.find(page => {
			const pathWithoutParams = pagePath.split('?')[0];
			return page.path === pathWithoutParams;
		});

		// 如果主包中没找到，查找分包
		if (!pageConfig) {
			for (const subPackage of pagesConfig.subPackages) {
				pageConfig = subPackage.pages.find(page => {
					const fullPath = `${subPackage.root}/${page.path}`;
					const pathWithoutParams = pagePath.split('?')[0];
					return fullPath === pathWithoutParams;
				});

				if (pageConfig) break;
			}
		}
		let imageUrl = "https://img.aibbyp.com/wechatUser/yhfx.png";
		const shareTitle = pageConfig?.style?.navigationBarTitleText || '默认分享标题';
		console.log(shareTitle, imageUrl);
		// 设置转发的参数
		return {
			title: shareTitle,
			imageUrl: imageUrl,
			path: `/pages/tabbarcompotant/index/landlord?invitation_code=${uni.getStorageSync('wanlshop:user').uuid || ''}`,
			success: function(res) {
				console.log("share分享成功", res)
				if (res.errMsg == 'shareAppMessage:ok') {}
			},
			fail: function(res) {
				console.log("失败", res)
			}
		}
	},
	// 分享到朋友圈
	onShareTimeline: function(res) {
		return {

		}
	},
	// 收藏
	onAddToFavorites: function(res) {
		return {

		}
	}
}